
const oracledb = require('oracledb');
const dbconfig = require('../utils/dbconfig');

async function getUser2(){
    let connection;
    let userList = [];
    try{
        oracledb.initOracleClient({libDir:'D:\\soft\\instantclient_11_2_64\\instantclient_11_2'})
        connection = await oracledb.getConnection(dbconfig);

        const result = await connection.execute("select loginname,nick,ID,to_char(createtime,'yyyy-MM-dd HH:mm:ss') createtime from sys_user where DEL_FLAG='2'");
        //console.log(result.rows);
        if(result.rows){
            result.rows.forEach(row=>{
                //console.log(row);
                userList.push({
                    loginname: row[0],
                    nick: row[1],
                    id: row[2],
                    createtime:row[3]
                })
            })
            // xxwlList.forEach(x=>{
            //     console.log(x);
            //     console.log(JSON.stringify(x));
            // })
        }
    }catch(err){
        console.error(err);
    }finally{
        if(connection){
            try{
                await connection.close();
            }catch(err){
                console.error(err);
            }
        }
    }
    return {flag:true,data:userList};
}
async function getUser(){
    let connection;
    let userList = [];
    try{
        oracledb.initOracleClient({libDir:'D:\\soft\\instantclient_11_2_64\\instantclient_11_2'})
        connection = await oracledb.getConnection(dbconfig);

        const result = await connection.execute(`select djid,file_name,f_id,to_char(firsttime,'yyyy-MM-dd HH:mm:ss') createtime 
            from bgpt_common_b_fj where djid=:djid`,['5d0260765ef345af863608fd4c44bec8']);
        //console.log(result.rows);
        if(result.rows){
            result.rows.forEach(row=>{
                //console.log(row);
                userList.push({
                    loginname: row[0],
                    nick: row[1],
                    id: row[2],
                    createtime:row[3]
                })
            })
            // xxwlList.forEach(x=>{
            //     console.log(x);
            //     console.log(JSON.stringify(x));
            // })
        }
    }catch(err){
        console.error(err);
    }finally{
        if(connection){
            try{
                await connection.close();
            }catch(err){
                console.error(err);
            }
        }
    }
    return {flag:true,data:userList};
}


module.exports={
    getUser
}